package outbound_rcc_project

import (
	"context"
	"git.mycaigou.com/gfyx/common/tenant_db"
	"gorm.io/gorm"
)

type outBoundRccProjectRepository struct {
	tenant_db.TenantDB
}

func NewOutBoundRccProjectRepository() OutBoundRccProjectRepositoryIface {
	return &outBoundRccProjectRepository{}
}

func (r *outBoundRccProjectRepository) Save(ctx context.Context, po *GfyxOutboundRccProjectPo) (*GfyxOutboundRccProjectPo, error) {
	err := r.GetTenantDB(ctx).Table(po.TableName()).Save(po).Error
	if err != nil {
		return nil, err
	}
	return po, nil
}

func (r *outBoundRccProjectRepository) QueryOne(ctx context.Context, taskId int64, mobile, customerName string) (*GfyxOutboundRccProjectPo, error) {
	var result GfyxOutboundRccProjectPo
	err := r.GetTenantDB(ctx).Table(GfyxOutboundRccProjectPo{}.TableName()).Where("task_id = ? and mobile =? and customer_name =?", taskId, mobile, customerName).First(&result).Error
	if err != nil {
		if err == gorm.ErrRecordNotFound {
			return nil, nil
		}
		return nil, err
	}
	return &result, nil
}
